package com.chinasofti.sql;

import java.sql.*;


public class ConnSql {
    public  static Connection dbcon=null; //处理与特定数据库的连接
    public  static Statement stmt = null;// 执行语句
    public  static ResultSet rst = null;// 结果集
    public static void main(String[] args) {

    }
    public static void connect(){
        String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String dbURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=123";
        String userName="xiaoziyan";            //sqlserver用户名
        String userPwd="xiaoziyan";    //sqlserver用户密码

        try{
            Class.forName(driverName);   //加载sqlserver的驱动类
            System.out.println("加载SQLServer驱动类成功!");
        }
        catch(ClassNotFoundException a){
            System.out.println("加载SQLServer驱动失败!");
            a.printStackTrace();
        }
 /*       try{
            dbcon= DriverManager.getConnection(dbURL,userName,userPwd);
            System.out.println("数据库连接成功!");
        }
        catch(SQLException e){
            System.out.println("数据库连接失败!");
            e.printStackTrace();
        }*/
    }
 /*   public static int select(String name,String password){

        String sql="select count(*) as c from [123].[dbo].[user] where username='"+name+"' and password='"+password+"'";
        int i=0;
        try {
            stmt=dbcon.createStatement();
            rst=stmt.executeQuery(sql);
            while (rst.next()){
                i=Integer.parseInt(rst.getString("c"));

            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }*/
  /*  public static int insert (String name,String password) {
        if (name != ""&&password!="") {
            String sql = "insert into [123].[dbo].[user] (username,password) values ('" + name + "','" + password + "')";
            try {
                stmt = dbcon.createStatement();
                rst = stmt.executeQuery(sql);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            return 0;
        }else {
            return 1;
        }

        }*/

}
